<?php

namespace App\Http\Controllers\Api;

use App\Models\Artcat;
use App\Models\Article;
use App\Models\ArticleClass;
use App\Models\ArticleCommon;
use App\Models\Brand;
use App\Models\Collection;
use App\Models\Dict;
use App\Models\IntegralUsers;
use App\Models\LmColumn;
use App\Models\Provinces;
use App\Models\Service;
use App\Models\Subscribe;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BrandController extends Controller
{
    //
    public function index(Request $request)
    {
        $keys = $request->get('keys');
        $model = Brand::query();
        if ($keys) {
            $model = $model->where('title', 'like', '%' . $keys . '%');
        }
        $model = $model->where('type', 0);
        $model = $model->where('status', 1);
        $re = $model->orderBy('created_at', 'desc')->paginate(10);
        return showMsg('获取成功', 200, $re);
    }

    public function member(Request $request)
    {
        $keys = $request->get('keys');
        $model = Brand::query();
        if ($keys) {
            $model = $model->where('title', 'like', '%' . $keys . '%');
        }
        $model = $model->where('type', 1);
        $model = $model->where('status', 1);
        $re = $model->orderBy('created_at', 'desc')->paginate(10);
        return showMsg('获取成功', 200, $re);
    }

    public function details(Request $request)
    {
        $ids = $request->get('id');
        $re = Brand::where('id', $ids)->first();
        $re['content'] = get_img_thumb_url(addBaseUrlToMedia($re['content'], 'https://cloud.wxstores.com'));
        return showMsg('获取成功', 200, $re);
    }

    public function service(Request $request)
    {
        $cate_id = $request->get('cate_id', 0);
        $model = Service::query();
        if ($cate_id) {
            $model = $model->where('cate_id', $cate_id);
        }
        $re = $model->orderBy('sort', 'asc')->orderBy('created_at', 'desc')->paginate(10);
        $title = Dict::where(['dictname' => 'industry', 'dvalue' => $cate_id])->value('dkey');
        return showMsg($title, 200, $re);
    }

}
